package com.joysuch.wwyt.workflow.repository;

import com.joysuch.wwyt.workflow.entity.LocationVerifyRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author ZhaoQiuWei
 * @Date 2021/8/18 13:26
 */
public interface WorkFlowSignatureDao extends JpaRepository<LocationVerifyRecord, Long> {
    @Query(value = "SELECT * FROM wwyt_location_verify_record r INNER JOIN (SELECT MAX(id) id,tenent_id,org_code FROM wwyt_location_verify_record WHERE task_code = ?1 AND delete_flag = '0' GROUP BY component_key,component_name) t ON t.id=r.id ORDER BY r.id", nativeQuery = true)
    List<LocationVerifyRecord> findDistinctRecordByTaskCode(String taskCode);

    
    @Query(value = "SELECT * " +
            "from wwyt_location_verify_record " +
            "where group_id in (SELECT DISTINCT group_id " +
            "                   FROM wwyt_location_verify_record r " +
            "                            INNER JOIN ( " +
            "                       SELECT MAX(id) id, " +
            "                              tenent_id, " +
            "                              org_code " +
            "                       FROM wwyt_location_verify_record " +
            "                       WHERE task_code = ?1 " +
            "                         AND delete_flag = '0' " +
            "                       GROUP BY component_key, " +
            "                                component_name " +
            "                   ) t ON t.id = r.id " +
            "                   )ORDER BY id " , nativeQuery = true)
    List<LocationVerifyRecord> findAllByTaskCode(String taskCode);
    
}
